<template>
  <div id="vaas-orders">
    <div class="card bg-transparent">
      <div class="card-header bg-info text-white">
        机场服务订单（第三方服务）
      </div>
      <div class="card-body py-1">
        <form>
          <div class="row">
            <div class="col-1">
              <my-date-picker
                id="beginDate"
                v-model="beginDate"
                name="sc.beginDate"
                placeholder="开始日期"
              ></my-date-picker>
            </div>
            <div class="col-1">
              <my-date-picker
                id="endDate"
                v-model="endDate"
                name="sc.endDate"
                placeholder="截止日期"
              ></my-date-picker>
            </div>
            <div class="col-1">
              <input
                type="textfield"
                class="form-control"
                size="6"
                placeholder="服务单号"
                v-model.trim="orderNo"
              />
            </div>
            <div class="col-1">
              <select
                class="form-select"
                v-model.number="status"
                name="sc.status"
              >
                <option value="-1">所有</option>
                <option value="0">待处理</option>
                <option value="1">处理中</option>
                <option value="2">已完成</option>
                <option value="4">已取消</option>
              </select>
            </div>
            <div class="col-2">
              <my-select-customer
                :customerId.sync="customerId"
                :status="1"
              ></my-select-customer>
            </div>
            <div class="col">
              <button
                id="btnSearch"
                type="button"
                class="btn btn-primary ms-2"
                @click.stop="search()"
              >
                查找
              </button>
              <a
                href="javascript:void(0)"
                @click.stop="quickSearch(0)"
                class="small ms-1"
                >待处理</a
              >
              <button
                type="button"
                class="btn btn-secondary btn-sm ms-2"
                @click.stop="reset()"
              >
                重置
              </button>

              <router-link class="btn btn-success float-end" to="/vaas/order"
                >新建服务订单</router-link
              >
            </div>
          </div>
        </form>
      </div>

      <nav id="pagination-box-1" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>

      <vas-order-list :dataList="dataList"></vas-order-list>

      <nav id="pagination-box-2" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>
    </div>
  </div>
</template>

<script>
import { showPayType } from "@/common/common.js";
import { searchVasOrders, showVasOrderStatus } from "@/api/vas.js";
import MyDatePicker from "@/components/my-datepicker.vue";
import MyPagination from "@/components/my-pagination.vue";
import MySelectCustomer from "@/components/my-select2-customer.vue";
import VasOrderList from "@/components/list/vas-order-list.vue";

export default {
  components: {
    MyDatePicker,
    MyPagination,
    MySelectCustomer,
    VasOrderList,
  },
  data() {
    return {
      dataList: [],

      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 20,
        pageTotal: 0,
      },

      beginDate: "",
      endDate: "",
      status: -1,
      orderNo: "",
      customerId: -1,
      productCode: "",

      orderType: 1,
    };
  },
  mounted: function () {
    // this.search()
    if (window.matchMedia("(max-width: 576px)").matches) {
      console.log(this.$router);
      this.$router.replace("/h5/vaas/orders");
    } else {
      this.search();
    }
  },
  methods: {
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    search: function () {
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.beginDate": this.beginDate,
        "sc.endDate": this.endDate,
        "sc.status": this.status,
        "sc.orderNo": this.orderNo,
        "sc.customerId": this.customerId,
        "sc.productCode": this.productCode,
        "sc.orderType": this.orderType,
      };
      searchVasOrders(params, (v) => {
        this.dataList = v.dataList;
        this.sc = v.page;
        if (this.dataList.length === 0) {
          this.showErrMsg("未找到符合条件的数据");
        }
      });
    },
    quickSearch: function (status) {
      this.status = status;
      this.search();
    },
    getStatusDesc: function (status) {
      return showVasOrderStatus(status);
    },
    getPayTypeDesc: function (payType) {
      return showPayType(payType);
    },
    reset: function () {
      this.beginDate = "";
      this.endDate = "";
      this.status = -1;
      this.sc.pageNo = 1;
      this.orderNo = "";
      this.customerId = -1;
      this.productCode = "";
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>
